package com.clz.latte.delegate;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import me.yokeyword.fragmentation_swipeback.SwipeBackFragment;

/**
 * Created by Administrator on 2017/11/16.
 * Fragment的基类
 */

public abstract class BaseDeleGate extends SwipeBackFragment {

    private Unbinder mUnbinder = null;

    public abstract Object setLayOut();

    public abstract void onBindView(@Nullable Bundle savedInstanceState, View rootView);

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = null;
        if (setLayOut() instanceof Integer) {
            rootView = inflater.inflate((Integer) setLayOut(), container, false);
            Log.d("BaseDeleGate", rootView.getId() + "");
        } else if (setLayOut() instanceof View) {
            rootView = (View) setLayOut();
        } else {
            throw new ClassCastException("setlayout() type must be int or view");
        }
        if (null != rootView) {
            mUnbinder = ButterKnife.bind(this, rootView);
            onBindView(savedInstanceState, rootView);
        }
        return rootView;
    }

    public Activity getProxyActivity() {
        return _mActivity;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mUnbinder != null) {
            mUnbinder = null;
        }
    }
}
